/*******************************************************************************
 * Copyright (c) 2012 Daniele Parisi.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Daniele Parisi
 *     neb.inf@gmail.com
 *     http://www.danieleparisi.com/
 ******************************************************************************/
package org.jxreport.core.views.chart.line;

import java.util.LinkedList;
import java.util.List;

import org.jxreport.core.Table;
import org.jxreport.core.XMLValues;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Line{
    protected String label = null; 			// label to use in the legend for this line.
    protected String color = null;			// CSS color spec to use for the line.  Determined automatically.
    
    protected String lineWidth = "2";
    protected String showLine = "true";     // whether to render the line segments or not.
    protected String showMarker = "true";	// render the data point markers or not.
    
	protected MarkerOptions markerOptions = new MarkerOptions();
	protected List<Point> points = new LinkedList<Point>();

	public Line(Element lineElement, Table table)
	{
		NodeList all = lineElement.getElementsByTagName("*");
		for(int k = 0 ; k < all.getLength();k++) {
			Element childEl = (Element)all.item(k);

			if(childEl.getTagName().equals(XMLValues.LINE_LABEL))
				this.setLabel(childEl.getTextContent());

			if(childEl.getTagName().equals(XMLValues.LINE_COLOR))
				this.setColor(childEl.getTextContent());

			if(childEl.getTagName().equals(XMLValues.LINE_WIDTH))
				this.setLineWidth(childEl.getTextContent());
			
			else if(childEl.getTagName().equals(XMLValues.SHOW_LINE))
				this.setShowLine(childEl.getTextContent());
			
			else if(childEl.getTagName().equals(XMLValues.SHOW_MARKER))
				this.setShowMarker(childEl.getTextContent());
			
			else if(childEl.getTagName().equals(XMLValues.MARKER_OPTIONS))
			{
				NodeList nl2 = childEl.getElementsByTagName("*");
				for (int j = 0; j < nl2.getLength(); j++) {
					Element markerElement = (Element)nl2.item(j);
					if(markerElement.getTagName().equals(MarkerOptions.COLOR))
						this.markerOptions.setColor(markerElement.getTextContent());
					
					else if(markerElement.getTagName().equals(MarkerOptions.LINE_WIDTH))
						this.markerOptions.setLineWidth(markerElement.getTextContent());
					
					else if(markerElement.getTagName().equals(MarkerOptions.SHADOW))
						this.markerOptions.setShadow(markerElement.getTextContent());
					
					else if(markerElement.getTagName().equals(MarkerOptions.SHADOW_ALPHA))
						this.markerOptions.setShadowAlpha(markerElement.getTextContent());
					
					else if(markerElement.getTagName().equals(MarkerOptions.SHADOW_ANGLE))
						this.markerOptions.setShadowAngle(markerElement.getTextContent());
					
					else if(markerElement.getTagName().equals(MarkerOptions.SHADOW_DEPTH))
						this.markerOptions.setShadowDepth(markerElement.getTextContent());
					
					else if(markerElement.getTagName().equals(MarkerOptions.SHADOW_OFFSET))
						this.markerOptions.setShadowOffset(markerElement.getTextContent());
	
					else if(markerElement.getTagName().equals(MarkerOptions.SHOW))
						this.markerOptions.setShow(markerElement.getTextContent());
					
					else if(markerElement.getTagName().equals(MarkerOptions.SIZE))
						this.markerOptions.setSize(markerElement.getTextContent());
					
					else if(markerElement.getTagName().equals(MarkerOptions.STYLE))
						this.markerOptions.setStyle(markerElement.getTextContent());
				}
			}
			else if(childEl.getTagName().equals(XMLValues.POINT))
				this.points.add(new Point(childEl));
			
			else if(childEl.getTagName().equals(XMLValues.POINTS))
				this.points.addAll(Point.getPointsByData(childEl, table));
		}
	}

	public String getLineWidth() {
		return lineWidth;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public void setLineWidth(String lineWidth) {
		this.lineWidth = lineWidth;
	}

	public String getShowLine() {
		return showLine;
	}

	public void setShowLine(String showLine) {
		this.showLine = showLine;
	}

	public String getShowMarker() {
		return showMarker;
	}

	public void setShowMarker(String showMarker) {
		this.showMarker = showMarker;
	}

	public List<Point> getPoints() {
		return points;
	}

	public MarkerOptions getMarkerOptions() {
		return markerOptions;
	}

	public void setMarkerOptions(MarkerOptions markerOptions) {
		this.markerOptions = markerOptions;
	}

	public void setPoints(List<Point> points) {
		this.points = points;
	}
}
